from sqlalchemy import Column, INTEGER
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy_dm import VARCHAR2, DATE, NUMBER

# 创建对象的基类
Base = declarative_base()

# 评分评级类
class PfpjModel(Base):
    # 模式名
    __table_args__ = {'schema': 'ESUNTEST'}
    # 表名
    __tablename__ = 'HX_PFPJ'
    # 表结构
    ID = Column(INTEGER, primary_key=True, autoincrement=True)
    CUST_ID = Column(VARCHAR2(100))
    CUST_NAME = Column(VARCHAR2(255))
    CREDIT_NO = Column(VARCHAR2(255))
    CHECK_DATE = Column(VARCHAR2(100))
    END_SCORE = Column(NUMBER(2,0))
    GRADE_RESULT = Column(VARCHAR2(100))

    @classmethod
    def from_dict(cls, data):
        return cls(
            ID=data['ID'],
            CUST_ID=data['CUST_ID'],
            CUST_NAME=data['CUST_NAME'],
            CREDIT_NO=data['CREDIT_NO'],
            CHECK_DATE=data['CHECK_DATE'],
            END_SCORE=data['END_SCORE'],
            GRADE_RESULT=data['GRADE_RESULT']
        )

    def to_dict(self):
        return {
            'ID': self.ID,
            'CUST_ID': self.CUST_ID,
            'CUST_NAME': self.CUST_NAME,
            'CREDIT_NO': self.CREDIT_NO,
            'CHECK_DATE': self.CHECK_DATE,
            'END_SCORE': self.END_SCORE,
            'GRADE_RESULT': self.GRADE_RESULT
        }
